// pages/index/index.js
var app = getApp();
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		array: [],
		index: 0,
		img:'20190602062811930.png',
		imgURL: 'http://localhost/store/img/',
		goods: [],
    turns:[],
		i:0
	},

	bindPickerChange: function (e) {
		console.log('picker发送选择改变，携带值为', e.detail.value)
		console.log(this.data.array[e.detail.value].tId);
		let tid = this.data.array[e.detail.value].tId;
		this.setData({
			index: e.detail.value
		})
		this.requestGoods(tid);
	},

  requestTurns: function (tid) {
    var $this = this;
    // console.log(this);
    wx.request({
      url: app.globalData.baseURL + 'Info/getTurnList',
      method: 'POST',
      data: {
        'tid': tid
      },
      header: {

      },
      success: function (res) {

        $this.setData({
          turns: res.data
        });


        // console.log(res.data);
        // console.log(this);

      }
    })
  },

	requestGoods: function(tid) {
		var $this=this;
		// console.log(this);
		wx.request({
			url: app.globalData.baseURL +'Info/getGoodsList',
			method: 'POST',
			data: {
				'tid': tid
			},
			header: {

			},
			success: function(res){
        
          $this.setData({
            goods: res.data
          });

        
				// console.log(res.data);
				// console.log(this);
			
			}
		})	
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		var $this = this;
		wx.request({
			url: app.globalData.baseURL +'Info/types',
			method: 'POST',
			data: {},
			header: {

			},
			success: function(res){
				// console.log(res.data);
				$this.setData({
					array: res.data
				})
			}
		});
		this.requestGoods(0);
    this.requestTurns(0);
	},
  
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		this.requestGoods(0);
    this.requestTurns(0);
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {
		wx.startPullDownRefresh();
		this.onLoad();
		wx.stopPullDownRefresh();
	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	},
	detail: function (e){
		let gid = e.currentTarget.id;
		app.dodetail(gid);
	},
  tdetail: function (e) {
    let nid = e.currentTarget.id;
    app.dotdetail(nid);
  },
  search: function (e) {
    // console.log(e);
    wx.navigateTo({
      url: '../search/search',
    })
  },
  posts: function (e) {
    // console.log(e);
    wx.navigateTo({
      url: '../posts/posts',
    })
  },
  evalua: function (e) {
    // console.log(e);
    wx.navigateTo({
      url: '../evalua/evalua',
    })
  },
	send:function(e){
		let u = app.globalData.userInfo;
		if(u!=null){
			wx.navigateTo({
				url: '../send/send'
			});
		}else{
			wx.showToast({
				title: '请登陆后再来',
				icon: 'none',
				duration: 1000
			});
		}
	}
})